﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.dtn.deals;
using System.Data;
using System.Security.Cryptography;

public partial class Login_Proc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        try
        {
            Itbl_MemberManager objMem = tbl_MemberManager.CreateInstance();
            string pass = Request.Form["pass"].ToString();
            string username = Request.Form["username"].ToString();
            string remember = Request.Form["rem"].ToString();
            //if (captcha == Session["CaptchaImageText"].ToString())
            //{
            string sql = "username = '" + username.Trim() + "' and pass = '" + pass+ "'";
            DataTable dt = objMem.Selecttbl_MembersDynamic(sql, "memberID");//N'username=''dda'' and pass=''12'''
	//	EncryptionPass(pass)	"\b?_???q????\"\0?'"	string

            if (dt != null && dt.Rows.Count > 0)
            {
                if (remember.Equals("1"))
                    tbl_MemberManager.LogInCookie(dt.Rows[0]["username"].ToString());
                Session["UserName"] = dt.Rows[0]["username"].ToString();
              //  Session["Name"] = string.IsNullOrEmpty(dt.Rows[0]["fullName"].ToString()) == true ? dt.Rows[0]["fullName"].ToString() : dt.Rows[0]["phone"].ToString();
                Session["UserId"] = dt.Rows[0]["memberID"].ToString();
                Response.Write("0");
            }
            else
            {
                Response.Write("-2");
            }


        }
        catch (Exception se)
        {
            Response.Write("-1");
        }

    }


    public string EncryptionPass(string password)
    {
        string passEncryp = "";
        byte[] dataToHash_Bytes = System.Text.Encoding.Unicode.GetBytes(password);
        MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
        byte[] md5_Bytes = md5.ComputeHash(dataToHash_Bytes);
        passEncryp = System.Text.Encoding.ASCII.GetString(md5_Bytes);

        return passEncryp;

    }
}